package com.yulongtian.principles.demo02.before;

/**
 * @author YulongTian
 * @date 2022/7/8 - 14:36
 * 测试类
 */
public class RectangleDemo {
    public static void main(String[] args) {
        //创建长方形对象
        Rectangle rectangle=new Rectangle();
        //设置长和宽
        rectangle.setLength(20);
        rectangle.setWidth(10);

        //扩宽操作
        resize(rectangle);
        printLengthAndWidth(rectangle);

        System.out.println("============================");
        //创建正方形对象
        Square square=new Square();
        //设置长和宽
        square.setLength(10);
        //扩宽操作
        resize(square);
        printLengthAndWidth(square);
    }

    //扩宽方法
    public static void resize(Rectangle rectangle) {
        //判断宽如果比长小，则进行扩宽操作
        while (rectangle.getWidth() <= rectangle.getLength()) {
            rectangle.setWidth(rectangle.getWidth() + 1);
        }

    }

    //打印长和宽
    public static void printLengthAndWidth(Rectangle rectangle){
        System.out.println("长:"+rectangle.getLength());
        System.out.println("宽:"+rectangle.getWidth());
    }

}
